﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Warehouse_Bar_Code
{
    public partial class 供应商信息 : Form
    {
        public 供应商信息()
        {
            InitializeComponent();
        }
        private void Provider_Load(object sender, EventArgs e)
        {

            //取消自动列
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = DBH.Select("select * from Provider");

        }

        private void button1_Click(object sender, EventArgs e)
        {

            string PName = textBox1.Text;
            string sql = $"select * from Provider where PName like '%{PName}%'";
            //取消自动列
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = DBH.Select(sql);


        }

        private void 添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           供应商信息添加或者修改 PA = new 供应商信息添加或者修改();
            PA.f = this;
            PA.Show();
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            供应商信息添加或者修改 pa = new 供应商信息添加或者修改();
            pa.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
            pa.PName = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            pa.Phone = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
            pa.Address = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
            pa.f = this;
            pa.Show();
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
            string sql = "delete from Provider where Id=" + Id;
            if (DBH.NoSelect(sql) > 0)
            {
                MessageBox.Show("删除成功！");
                Provider_Load(null, null);
            }
            else
            {
                MessageBox.Show("删除失败！");
            }
        }
    }
}
